from itertools import count

even_list = list(range(2,101,2))
print(even_list)
for i in range(len(even_list)):
    even_list[i] = even_list[i]**2
    print(even_list)
for j in range(len(even_list)-1, -1, -1):
    if even_list[j] > 1000:
        del even_list[j]
        print(even_list)

even_list.reverse()
print(even_list)

print(even_list[:10])

new_list = [101,102,103]
even_list.extend(new_list)
print(even_list)

average = sum(even_list) / len(even_list)
print(average)

max_val = max(even_list)
min_val = min(even_list)
print(max_val,min_val)

if 11 in even_list:
    index_11 = even_list.index(11)
    print(index_11)
else:
    print("列表中不存在11")

list_char1 = []
for i in range(len(even_list)):
    list_char1.append(str(even_list[i]))
print(list_char1)

even_list_float = [float(num) for num in even_list]
print(even_list_float)

count_gt50 = len([num for num in even_list if num > 50])
print(count_gt50)

even_list.insert(2, 99)
print(even_list)

even_list.pop()
print(even_list)

double_list = [num * 2 for num in even_list]
print(double_list)

part1 = [num for num in even_list if num <= 50]
part2 = [num for num in even_list if num > 50]
print(part1,part2)

list_to_dict = {elem: idx for idx, elem in enumerate(even_list)}
print(list_to_dict)
count = 0
for key, value in list_to_dict.items():
    if count < 5:
        print(f"{key}: {value}", end=" | ")
    count += 1
print()

for idx, elem in enumerate(even_list):
    if idx < 10:
        print(f"索引{idx}: 元素{elem}")

import random
random_elem = random.choice(even_list)
print(random_elem)

with open("a.txt", "w", encoding="utf-8") as f:
    for elem in even_list:
        f.write(str(elem) + "\n")



